function tSeries = generateRunoffTS(param,sS)
%
% Tobias Siegfried, 13.04.2007
% revision 10/08/2008

if sS
    randn('seed',param.randS);
end
tSeries = zeros(param.tEnd,param.nTS);
for ts = 1:param.nTS
    % Generate streamflow into domain (alpha_{i}*R_{->i})
    cpNew = zeros(param.tEnd,1);
    cpOld = cpNew;
    for t = 1:param.tEnd
        if t == 1
            temp = streamflowARM(param.muS(ts) + param.sigmaS*randn,param.muS(ts),param.rhoS,param.sigmaS,t);
            %if temp < 0 % avoid negative flows
            %    cpNew(t) = 0;
            %else
            if param.hydroGuy(ts)
                cpNew(t) = temp + param.nDaysPerMonth*sin(2*pi*(t+param.nDays/2)/param.nDays+pi);
            else
                cpNew(t) = temp + param.nDaysPerMonth*sin(2*pi*t/param.nDays+pi);
            end
                %cpNew(t) = sin(2*pi*t/param.nDays+pi);
            %end
        else
            temp = streamflowARM(cpNew(t-1),param.muS(ts),param.rhoS,param.sigmaS,t);
            %if temp < 0 % avoid negative flows
            %    cpNew(t) = 0;
            %else
            if param.hydroGuy(ts)
                cpNew(t) = temp + param.nDaysPerMonth*sin(2*pi*(t+param.nDays/2)/param.nDays+pi);
            else
                cpNew(t) = temp + param.nDaysPerMonth*sin(2*pi*t/param.nDays+pi);
            end
            %cpNew(t) = temp + sin(2*pi*t/param.nDays+pi);
                %cpNew(t) = sin(2*pi*t/param.nDays+pi);
            %end
        end
    end
    tSeries(:,ts) = cpNew;
end
tSeries(tSeries<0) = 0;